﻿using System.Windows;
using System.Windows.Controls;
using Assergs.Windows;

namespace BookvarWpf.Windows
{
    /// <summary>
    /// Interaction logic for ErrorWindow.xaml
    /// </summary>

    public partial class ErrorWindow
    {
        private Panel previousRoot;
        public ErrorWindow()
        {
            InitializeComponent();
        }

        void CopyToClipboardClicked(object sender, RoutedEventArgs e)
        {
            Clipboard.SetText(ErrorMessage);
        }
        void SendErrorClicked(object sender, RoutedEventArgs e)
        {
            previousRoot = ToolWindow.ModalContainerPanel;
            ToolWindow.ModalContainerPanel = root;
            errorDetails.Visibility = Visibility.Collapsed;
            var window = new SubmitBugWindow();
            root.Children.Add(window);
            window.Parent = root;
            window.Closed += window_Closed;
            
            window.StartPosition = ToolWindowStartPosition.Manual;
            window.Width = root.Height;
            window.Height = root.Width;
            window.BugDescription = ErrorMessage;
            window.BugTitle = "Application Error";
            window.ShowModalDialog();
        }

        void window_Closed(object sender, RoutedEventArgs e)
        {
            errorDetails.Visibility = Visibility.Visible;
            root.Children.Remove(sender as SubmitBugWindow);
            ToolWindow.ModalContainerPanel = previousRoot;
        }

        private string errorMessage;

        public string ErrorMessage
        {
            get { return errorMessage; }
            set 
            { 
                errorMessage = value;
                tbStack.Text = errorMessage;
            }
        }
    }
}